﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Innovator
{
	public class IEServiceContainer : IServiceProvider
	{
		//contains service types and services
		Dictionary<Type, object> services = new Dictionary<Type, object>();

		//add new service
		public void AddService(Type Service, object Provider)
		{
			if (services.ContainsKey(Service))
				throw new Exception("the service container already has a service provider of type " + Service.Name);
			this.services.Add(Service, Provider);
		}
		//get a service
		public object GetService(Type Service)
		{
			foreach (Type type in services.Keys)
				if (type == Service)
					return services[type];
			throw new Exception("the service provider does not contain a service provider of type " + Service.Name);
		}
		//get service shortcut
		public T GetService<T>()
		{
			object result = GetService(typeof(T));
			if (result != null)
				return (T)result;
			return default(T);
		}
		//remove service
		public void RemoveService(Type Service)
		{
			if (services.ContainsKey(Service))
				services.Remove(Service);
		}
		public bool ContainsService(Type Service)
		{
			return services.ContainsKey(Service);
		}
	}
}